#!/usr/local/bin/python

import sys

filename = sys.argv[1]
blast_type = sys.argv[2]

f = open(filename, "r")

def fmt(f):
    st = '{0:.4}'.format(f)
    return st

lines = f.readlines()

if len(lines) == 0:
    print sys.argv[1], "\t", "empty"
else:
    st = lines[0]
    line = st.split('\t')
    if blast_type == "blastp":
        query = float(line[6])
        hit = float(line[10])
        percentLength = (query / hit) * 100
    elif blast_type == "blastx":
        if float(line[8]) > float(line[7]):
            query = (float(line[8]) - float(line[7]) + 1) / 3
        else:
            query = (float(line[7]) - float(line[8]) + 1) / 3
        hit = float(line[10])
        percentLength = (query / hit) * 100
    else:
        print "Please indicate blastp or blastx"
    print sys.argv[1], "\t", int(query), "\t", int(hit), "\t", fmt(percentLength)

f.close()

